12. Exercise: Back Stack Manipulation
L3 18 Changing The Way We Go Back SCA V3 V3
Now it’s your turn to complete this exercise!
For the action connecting the gameFragment to the gameOverFragment, set the pop behavior to popTo gameFragment inclusive
Go to the navigation editor and select the action for navigating from the GameFragment to the GameOverFragment. Select PopTo GameFragment in the attributes pane with the inclusive flag to tell the Navigation component to pop fragments off of the fragment back stack until it finds the GameFragment, and then pop off the gameFragment transaction.
For the action connecting the gameFragment to the gameWonFragment, set the pop behavior to popTo gameFragment inclusive
Do the same thing with action from the GameFragment to the to the GameWonFragment.
Add the following actions with pop behavior set to PopTo TitleFragment exclusive
an action connecting the gameOverFragment to the gameFragment
an action connecting the gameWonFragment to the gameFragment
Add an action connecting the gameOverFragment to the gameFragment, and from the gameWonFragment to the game fragment. For each fragment, Select PopTo TitleFragment with the inclusive flag turned off.
Add an onClick Handler for the tryAgain button that navigates to the gameFragment
Add an onClick Handler for the nextMatch button that navigates to the gameFragment
And you’ve now implemented all of the navigation we’ll do with buttons.
If you want to start at this step, you can download this exercise code from: Step.04-Exercise-Back-Stack-Manipulation.
You will find plenty of //TODO comments to help you complete this exercise, and if you get stuck, go back and watch the video again.
Once you’re done, you can check your solution against the solution we’ve provided here Step.04-Solution-Back-Stack-Manipulation or git diff.
Task Description:
Match user expectations with back stack manipulation. Check the steps below as you implement them to complete this exercise.
Task Feedback:
Great! You’ve learned how to manipulate the back stack.
Solution: Step.04-Solution-Back-Stack-Manipulation or git diff